package com.zzyq.pc.utils;

import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	public static String printDate(Calendar calendar) {
		return sdf.format(calendar.getTime());
	}

	public static String printDate(Date date) {
		return sdf.format(date);
	}

	public static String printDate(Date date, String format) {
		return new SimpleDateFormat(format).format(date);
	}

	/**
	 * 将字符串转化为日期
	 */
	public static Date paraseStringToDate(String timestr) {
		return paraseStringToDate(timestr, "yyyy-MM-dd");
	}

	/**
	 * 将字符串转化为日期
	 */
	public static Date paraseStringToDate(String timestr, String format) {
		Date date = null;
		Format f = new SimpleDateFormat(format);
		try {
			date = (Date) f.parseObject(timestr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

}
